Added ability to pass an object to formParams to (re)populate a form.#90
Added ability to pass an object to formParams to (re)populate a form.#90justinbmeyer merged 3 commits intojupiterjs:masterfrom
Conversation
…a form. In other words, formParams is now a getter and a setter.
dom/form_params/form_params.js
Outdated
There was a problem hiding this comment.
I would love have some low level populate functionality. Was running into that again today (specifically populating Controllers that expose .val() method) and with Model + Observe it would be really easy to tie forms and models both ways. I am not sure if it takes care of nested params at the moment though. Wouldn't it return
params['test[key]']
instead of
params.test.key
?
var name = $(this).attr("name"), parts = name.match(keyBreaker),
value = params;
for(var i = 0; i < parts.length; i++) {
if(value[parts[i]]) {
value = value[parts[i]];
} else {
return '';
}
}
There was a problem hiding this comment.
Good call! Names using bracket notation, e.g. foo[] aren't handled. I'll add that to my next commit on this.
There was a problem hiding this comment.
Sweet. I can add some tests if you want.
There was a problem hiding this comment.
This function has it's if ( value ) condition and it can lead to errors. For example if you want to switch current edited item and it's field is empty then if(value) is false and last edited value stays.
This condition isn't necessary .
There was a problem hiding this comment.
@selecton Good catch. I assume if ( value !== undefined) would be the proper test. I'll make the changes now.
Added ability to pass an object to formParams to (re)populate a form.
Pretty straight forward -- thoughts?